package com.gblfy.lyrabbitmq.config;

import com.gblfy.lyrabbitmq.consts.MQPrefixConst;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * RabbitMQ 交换机和队列绑定配置类
 *
 * @author gblfy
 * @Date 2021-09-28 9:59
 */
@Configuration
public class RabbitTopicConfig {

    @Bean
    TopicExchange topicExchange() {
        return new TopicExchange(MQPrefixConst.WS_EXCEHANGE, true, false);
    }

    @Bean
    Queue hisUQ() {
        return new Queue("ly_mq_fai_q");
    }

    @Bean
    Binding hisUQBinding() {
        //ly-his.# 代表路由规则 表示如果路由的 routingKey 是以ly-his 开头就会发送到 ly_mq_his_u_q 这个队列上
        return BindingBuilder.bind(hisUQ()).to(topicExchange()).with("ly-fai.#");
    }
}
